<%@page import="java.util.HashMap"%>
<%@page import="com.license.servlets.UserServlet"%>
<%@page import="com.license.servlets.RecomandOptServlet"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.List"%>
<%@page import="com.license.logic.alimentation.Food"%>
<%@page import="com.license.logic.preference.Activity"%>
<%@include file="AdminBasePage.jsp"%>
<f:view>
	<html>
	<% 	UserServlet userServlet = new UserServlet();
	  	String psoValues = userServlet.getPSOExecutionTimes();
	  	String clonalValues = userServlet.getClonalExecutionTImes();
	  	RecomandOptServlet recomandOptServlet = new RecomandOptServlet();
	  	String foodDistribution = recomandOptServlet.getFoodDistribution(request, response);%>
	  	<%Map details = recomandOptServlet.getDetails(request, response); %>
	<body onload="createPieChart(&quot;<%=foodDistribution%>&quot;); wait();">
	<div class="span9">
	<div id="loading_screen">
  		<h1>Rendering...</h1>
  		<h3>Please Wait...</h3>
	</div>
	<script type="text/javascript" src="../jquery.jqplot.min.js"></script>
	<link class="include" rel="stylesheet" type="text/css" href="../jquery.jqplot.min.css" />
	<script class="include" type="text/javascript" src="../jqplot.pieRenderer.min.js"></script>	
	<%Map alldays = recomandOptServlet.printLifeStyleRecomandation(request, response); %>
	<%Map clasificationResult = recomandOptServlet.classify(request, response);%>


	<div class="row-fluid">
		<div class="block" style="width:870px;" >
			<p class="block-heading" data-toggle="collapse"
				data-target="#chart-container"><h3>Food Distribution Chart</h3></p>
			<div id="chart-container" class="block-body collapse in" style="width:870px;">
				<div id="pie1" style="margin-top:20px; margin-left:20px; width:400px; height:300px;"></div>
				<div id="deail" style="margin-top:-300px; margin-left:460px; width:600px; height:300px;">
					<div class="row-fluid">
						<div class="block" style="width:870px;" >
						<p class="block-heading" data-toggle="collapse"
							data-target="#chart-container"><h4>Behaviour Status</h4></p>
						<i><b>Classification result : </b></i>
						<br>
						<%String behaviour = (Double)clasificationResult.get("healtyStatus") == 1.0 ? "healty" : "unhealty";
			 			Double prob = 0.0;
						if(behaviour.equalsIgnoreCase("healty")) {
			 			prob =(Double)clasificationResult.get("healtyProbability");
			 			} else {
			 			prob =(Double)clasificationResult.get("unHealtyProbability");
			 			}%>
						<i>The behavior is <%=behaviour %> with the probability of <%=prob %></i>
						<br>
						<i><b>Details : </b></i>
						<br>
						<i>The correct amount of calories per day is <%=details.get("desireCalories")%></i>
						<br>
						<i>The amount of calories from generated menu per day is: <%=details.get("totalCaloriesPerDay") %></i>
						<br>
					</div>
				</div>
				</div>
			</div>
		</div>
	</div>



	<div class="row-fluid">
		<div class="block span6" style="width:870px;">
			<div class="block-heading" data-toggle="collapse"
				data-target="#widget1container"><h3>Recomanded menu for 7 day's</h3></div>
			<div id="widget1container" class="block-body collapse in">


				<div id="myCarousel" class="carousel slide" style="width:870px;">
					<!-- Carousel items -->
					<div class="carousel-inner">
						<%for(int i=1; i<=7;i++) { %>
						<%if(i==1) {%>
						<div class="active item">
						<%} else { %>
						<div class="item">
						<%} %>
							<h5>Day <%=i %></h5>
							<table class="table" id="recomandation_table">
								<thead>
								<% Map day1 = (Map)alldays.get("day"+i); %>
								<tr>
									<th colspan="2">Breakfast</th>
									<th style="width: 20px;"></th>
								</tr>
								</thead>
								<tbody>
									<tr>
										<td><h5>Food</h5></td>
										<td><h5>Grams</h5></td>
										<td><h5>Kalory</h5></td>
									</tr>
								<% for(Food foodItem :  (List<Food>)day1.get("breakfast")) { %>
									<tr>
										<td><%=foodItem.getName()%></td>
										<td><%=foodItem.getPortions() * foodItem.getCharacteristics().getGramsPerPortion()%></td>
										<td><%=foodItem.getCharacteristics().getKalory() * foodItem.getPortions()%>
										<td style="width : 40px;"></td>
									</tr>										
									<%}%>
								</tbody>
							</table>
							<table class="table" id="recomandation_table">
								<thead>
								<tr>
									<th colspan="2">Lunch</th>
									<th style="width: 20px;"></th>
								</tr>
								</thead>
								<tbody>
									<tr>
										<td><h5>Food</h5></td>
										<td><h5>Grams</h5></td>
										<td><h5>Kalory</h5></td>
									</tr>
								<% for(Food foodItem :  (List<Food>)day1.get("lunch")) { %>
									<tr>
										<td><%=foodItem.getName()%></td>
										<td><%=foodItem.getPortions() * foodItem.getCharacteristics().getGramsPerPortion()%></td>
										<td><%=foodItem.getCharacteristics().getKalory() * foodItem.getPortions()%>
										<td style="width : 40px;"></td>
									</tr>										
									<%}%>
								</tbody>
								<table class="table" id="recomandation_table">
								<thead>
								<tr>
									<th colspan="2">Snack</th>
									<th style="width: 20px;"></th>
								</tr>
								</thead>
								<tbody>
									<tr>
										<td><h5>Food</h5></td>
										<td><h5>Grams</h5></td>
										<td><h5>Kalory</h5></td>
									</tr>
								<% for(Food foodItem :  (List<Food>)day1.get("snack")) { %>
									<tr>
										<td><%=foodItem.getName()%></td>
										<td><%=foodItem.getPortions() * foodItem.getCharacteristics().getGramsPerPortion()%></td>
										<td><%=foodItem.getCharacteristics().getKalory() * foodItem.getPortions() %>
										<td style="width : 40px;"></td>
									</tr>										
									<%}%>
								</tbody>
							</table>
							<table class="table" id="recomandation_table">
								<thead>
								<tr>
									<th colspan="2">Dinner</th>
									<th style="width: 20px;"></th>
								</tr>
								</thead>
								<tbody>
									<tr>
										<td><h5>Food</h5></td>
										<td><h5>Grams</h5></td>
										<td><h5>Kalory</h5></td>
									</tr>
								<% for(Food foodItem :  (List<Food>)day1.get("dinner")) { %>
									<tr>
										<td><%=foodItem.getName()%></td>
										<td><%=foodItem.getPortions() * foodItem.getCharacteristics().getGramsPerPortion()%></td>
										<td><%=foodItem.getCharacteristics().getKalory() * foodItem.getPortions() %>
										<td style="width : 40px;"></td>
									</tr>										
									<%}%>
								</tbody>
							</table>
							<table class="table" id="recomandation_table">
								<thead>
								<tr>
									<th colspan="2">Phisical Activities</th>
									<th style="width: 20px;"></th>
								</tr>
								</thead>
								<tbody>
									<tr>
										<td><h5>Activitie</h5></td>
										<td><h5>Minutes</h5></td>
										<td><h5>Burned calories</h5></td>
									</tr>
								<%  List<Activity> activities = (List<Activity>)day1.get("phisicalActivity");
									if(activities != null) {
									for(Activity activity :  activities) { 
									if(activity != null) {%>
									<tr>
										<td><%=activity.getName()%></td>
										<td><%=activity.getMinutes()%></td>
										<td><%=activity.getKaloriesConsumed()%>
										<td style="width : 40px;"></td>
									</tr>										
									<%}}}%>
								</tbody>
							</table>
						</div>
						<%} %>
					</div>
					<!-- Carousel nav -->
					<a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
					<a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>
				</div>
			</div>
		</div>
	</div>

</div>
</div>
<footer>
	<hr>
	<!-- Purchase a site license to remove this link from the footer: http://www.portnine.com/bootstrap-themes -->
	<p class="pull-right">
		Procadio <a href="#" target="_blank">best lifestile recomandation
			software</a>
	</p>
	<p>
		&copy; 2013 <a href="#">Cozac Adrian & Mesaros Ionut</a>
	</p>
</footer>
<!-- Le javascript
    ================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
</body>
</html>
</f:view>